

 class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
         this.left = left;
          this.right = right;
      }
  }

class T {
    public TreeNode invertTree(TreeNode root) {


        invert(root);
        return root;

    }

    private void invert(TreeNode root){
        if(root==null){
            return;
        }

        TreeNode left=root.left;
        TreeNode right=root.right;

        root.left=right;
        root.right=left;

        invert(left);
        invert(right);

    }
}